package common;
import java.sql.*;

/**
 * Abstracts paged display's business logic
 */
public abstract class PageBusiness
{
    protected java.util.Vector v; //data need to display
    protected java.util.Vector v2; //data need to display

    /**
     * get the total number of records
     */
    public abstract int getAvailableCount()throws Exception;

    /**
     * get the data need to display
     */
    public java.util.Vector getResult()throws Exception
    {
        return v;
    }
    
    public java.util.Vector getResult2()throws Exception
    {
        return v2;
    }

    /**
     * helper method: get total number of records in a specified table
     */
    protected final int getAvailableCountHelper(Connection conn, String tableName) throws Exception
    {
        int ret = 0;
        Statement stmt = conn.createStatement();
        String strSql = "select count(*) from " + tableName;
        ResultSet rset = stmt.executeQuery(strSql);
        while(rset.next())
        {
            ret = rset.getInt(1);
        }
        return ret;
    }

    /**
     * execute database operations, return PageBean object containing the needed data
     */
    public abstract PageBean listData(String page)throws Exception;

}
